<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    function quickSort(arr){
        // 后续操作可能会删除原数组中的元素 => 为了不影响原数组 => 对数组进行深复制(浅拷贝)
        if(arr.length <= 1){
            return arr;
        }

        arr = arr.slice();  
        var midIndex = Math.floor(arr.length/2);
        var mid = arr.splice(midIndex,1)[0]; // [26][0]
        var left = [];
        var right = [];
        for(var i = 0;i<arr.length;i++){
            var item = arr[i];
            if(item>mid){
                right.push(item);
            }else{ // item <= mid
                left.push(item);
            }
        }
        console.log(left,mid,right);

        return quickSort(left).concat(mid,quickSort(right));
    }

    // quickSort([25,12,48,26,39,2,29]);
    quickSort([25,12,48,26,39,2,13,22,29]);



</script>
</html>